import { readFileSync } from "fs";
import { join } from "path";

var root: string = process.cwd();
export function getRoot() {
    return root;
}

export function setRoot($root: string) {
    root = $root;
}

export function getPkg(): { version: string } {
    let pkgStr = readFileSync(join(getRoot(), "package.json"));
    if (pkgStr) {
        return JSON.parse(pkgStr.toString());
    }
    return {
        version: "0.0.1"
    };
}

export var processArg: any = {};
for (let i = 2; i < process.argv.length; i++) {
    let str = process.argv[i];
    str = str.substr(1);
    let arr = str.split("=");
    processArg[arr[0]] = arr[1] || true;
}

export interface IProjectVo {
    dir?: string,                    //目录
    name: string,                    //项目名
    type: EnumProjectType,           //项目类型
    excludeCompress?: string[],      //发布压缩图片的排除列表
}

export interface IPublishVo {
    name?: string,
    type?: EnumPublishType,
    content?: any,
    fromPath?: string,
    toPath?: string,
    unCompessJs?:boolean,
    plat?: string,
    config?: string,
    preVersion?: string,
    compressImg?: boolean,
    localRes?: boolean
}

export enum EnumProjectType {
    Laya1,                       //laya1.0版本代码
    Laya2,                       //laya2.0版本代码
    Cocos,                       // cocos代码
}

export enum EnumPublishType {
    WxMiniGame,
    Web,
    FaceBook,
    WebApk,
    QQ,
    Vivo,
    Oppo,
    Baidu,
    TouTiao,
    HuaWei,
    Bili,
    KuGou,
    IOS,
    XiaoMi
}